//
//  OYVistorController.swift
//  weiboCopycat
//
//  Created by Orange Yu on 2016/12/1.
//  Copyright © 2016年 Orange Yu. All rights reserved.
//

import UIKit

class OYVistorController: UITableViewController {

    // 定义一个存储登录状态的变量
    let isLogin: Bool = OYUserInfoViewModel.sharedUserInfo.isLogin
    
    var visitorView: OYVisitorView?
    
    override func loadView() {
        super.loadView()

        if isLogin == true {
            // 如果已经登录

            print("已经登录")
            
        } else {
            // 如果没有登录
            visitorView = OYVisitorView()
            view = visitorView
            
            visitorView?.loginCallBack = {
                self.loginAction()
            }
            
            
            visitorView?.registerCallBack = {
                self.registerAction()
            }
            
            setupNavUI()
        }
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
     
    }
    
    func setupNavUI() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: #selector(loginAction))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(registerAction))
    }
    
    func loginAction() {
        
        let oauthVc: OYOauthController = OYOauthController()
        let naviVc = OYNavigationController(rootViewController: oauthVc)
        
        self.present(naviVc, animated: true, completion: nil)
    
    }
    
    func registerAction() {
        print("点击了注册")
    }

    

}
